$(document).ready(function() {
	//初始化数据
	init(1);
});
//默认加载  
function init(pageNo){
	var userId=getvl("userId");
	//获取信息列表
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/order/jpa/pageByUser?pageNum="+pageNo+"&pageSize="+pageSize+"&userId="+userId,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.list,function(i,n){							
					var id = n.id;
					var orderStatus=orderStatusStr(n.orderStatus);			
					if(n.orderMark==undefined){
						n.orderMark="无";
					}
					if(n.sendMoney==null){
						n.sendMoney="无";
					}
					var ride;
					if(n.orderStatus ==1 || n.orderStatus==8 ||n.orderStatus==0){
						ride="无";
					}else{
						ride=n.ride.realName;
					}
					var thislist = 
					'	<tr>'+
					'		<td>'+(i+1)+'</td>'+					
					'		<td>'+n.orderNumber+'</td>'+
					'		<td>'+n.gmtDatetime+'</td>'+
					'		<td>'+n.shop.nickName+'</td>'+					
					'		<td>'+ride+'</td>'+	
					'		<td>'+n.sendMoney+'</td>'+		
					'		<td>'+n.orderTip+'</td>'+	
					'		<td>'+n.changeMoney+'</td>'+							
					'		<td>'+n.orderMark+'</td>'+						
					'	</tr>';
					$('#thislist').append(thislist);																								
				});
				$('#thiscount').text(data.data.total);
				$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 				
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});
}	
//回调函数  
PageClick = function(pageclickednumber) {  
    init(pageclickednumber); 
}

/**
 * 用户状态返回
 * @param {Object} userStatus
 */
function orderStatusStr(orderStatus){
	if (orderStatus==1) {
		orderStatus = '待抢单';
	}else if(orderStatus==2) {
		orderStatus = '待取货';
	}
	else if(orderStatus==3) {
		orderStatus = '配送中';
	}
	else if(orderStatus==4) {
		orderStatus = '已送达';
	}
	else if(orderStatus==6) {
		orderStatus = '货物损坏';
	}
	else if(orderStatus==8) {
		orderStatus = '订单未抢取消';
	}
	else if(orderStatus==9) {
		orderStatus = '已抢未取货取消';
	}
	else if(orderStatus==10) {
		orderStatus = '已配送取消';
	}
	return orderStatus;
}



